package com.jic.market.impl;


import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.market.common.enums.DeleteFlagEnum;
import com.jic.market.entity.PromotionMutexShareShipModel;
import com.jic.market.mapper.PromotionMutexShareShipMapper;
import com.jic.market.service.PPromotionMutexShareShipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *   服务类
 *
 * @author xuyongliang
 * @since 2020-02-26
 */
@Service
public class PromotionMutexShareShipServiceImpl implements PPromotionMutexShareShipService{

    @Autowired
    private PromotionMutexShareShipMapper modelMapper;

    /**
     *  新增
     * @param modelEntity
     */
    @Override
    public Integer promotionMutexShareShipAdd(PromotionMutexShareShipModel modelEntity){
        return modelMapper.promotionMutexShareShipAdd(modelEntity);
    }

    /**
     *  编辑
     * @param modifyEntity
     * @param whereCondition
     */
    @Override
    public Integer promotionMutexShareShipEdit(PromotionMutexShareShipModel modifyEntity, PromotionMutexShareShipModel whereCondition){
        return modelMapper.promotionMutexShareShipEdit(modifyEntity, whereCondition);
    }

    /**
     *  删除
     * @param \
     */
    @Override
    public Integer promotionMutexShareShipDelete(Map map){
        return modelMapper.promotionMutexShareShipDelete(map);
    }

    /**
     *  查询详情
     * @param
     */
    @Override
    public PromotionMutexShareShipModel promotionMutexShareShipQuery(Map map){
        return modelMapper.promotionMutexShareShipQuery(map);
    }

    /**
     *  分页查询
     * @param
     */
    @Override
    public PageResult<PromotionMutexShareShipModel> promotionMutexShareShipQueryPageList(PromotionMutexShareShipModel modelEntity, Page pageQuery){
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<PromotionMutexShareShipModel> list = modelMapper.promotionMutexShareShipQueryPageList(startIndex, pageQuery.getLimit(), modelEntity);
        long count = modelMapper.promotionMutexShareShipQueryPageCount(modelEntity);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }

    /**
    *   修改单据状态
    *  @param \
    */
    @Override
    public Integer promotionMutexShareShipChangeStatus(Map map){
        return modelMapper.promotionMutexShareShipChangeStatus(map);
    }

    /**
     *   修改审批状态
     * @param \
     */
    @Override
    public Integer promotionMutexShareShipChangeApproveStatus(Map map){
        return modelMapper.promotionMutexShareShipChangeApproveStatus(map);
    }

    /**
     * 查询两个促销活动互斥共享情况
     * @param promotionFirst
     * @param promotionSecond
     * @return 互斥共享状态 返回值
     * @see       com.jic.market.common.constant.PromotionMutexConstants  返回值
     */
    @Override
    public Integer queryTwoPromotionsShipStatus(Integer promotionFirst, Integer promotionSecond) {
        Integer status =null;
        Map map =new HashMap(8);
        map.put("promFirst",promotionFirst);
        map.put("promSecond",promotionSecond);
        // 未删除标识
        map.put("deleteFlag", DeleteFlagEnum.UN_DELETE.getCode());
        PromotionMutexShareShipModel promotionMutexShareShipModel = modelMapper.promotionMutexShareShipQuery(map);
        if(promotionMutexShareShipModel !=null){
            status =promotionMutexShareShipModel.getStatus();
        }
        return status;
    }

}